/*
 * This file (AxAboutDlg.java) is protected by the GNU GPL licence (v2). 
 * Please read the license.txt attached for further informations. 
 * 
 */

package artx.gui;

import java.awt.Color;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Rectangle;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextPane;

import artx.utils.AxConstants;
import artx.utils.AxLog;

/**
 * Basic "About ..." dialog using Swing.
 * 
 * @author Xavier Gouchet
 * 
 */
public class AxAboutDlg extends JDialog implements AxConstants {

	private static final long serialVersionUID = 1L;

	private JPanel mainPanel = null;

	private JLabel aboutLogo = null;

	private JLabel aboutTitle = null;

	private JTextPane aboutText = null;

	/** Title used in the about dialog */
	protected String title = null;

	/** Text used in the about dialog */
	protected String about = null;

	/**
	 * @param owner
	 */
	public AxAboutDlg(Frame owner) {
		super(owner);
		String text = "<font face=\"Dialog\">&copy; Xavier Gouchet <em>(2008)</em><br/>"
				+ "<a href=\"mailto:xavier.gouchet@gmail.com\">xavier.gouchet@gmail.com</a><br/>"
				+ "<br/>More info available at : <a href=\"http://www.xgouchet.fr/\">"
				+ "http://www.xgouchet.fr/</a></font>";
		initialize("About " + TITLE, "About " + FULL_TITLE, text);
	}

	/**
	 * This method initializes this.
	 * 
	 */
	private void initialize(String t, String ft, String d) {
		this.setSize(420, 260);
		this.setTitle(t);
		this.title = new String(ft);
		this.about = new String(d);
		this.setContentPane(getMainPanel());
	}

	/**
	 * This method initializes the main content pane.
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getMainPanel() {
		if (mainPanel == null) {
			// create title
			aboutTitle = new JLabel();
			aboutTitle.setBounds(new Rectangle(8, 8, 392, 32));
			aboutTitle.setFont(new Font("Dialog", Font.BOLD, 18));
			aboutTitle.setText(this.title);

			// Create Logo
			aboutLogo = new JLabel();
			aboutLogo.setText("");
			aboutLogo.setBounds(new Rectangle(6, 46, 130, 162));
			String imgpath = "/artx/gui/rsc/logo.png";
			URL u = ImageIcon.class.getResource(imgpath);
			if (u != null) {
				aboutLogo.setIcon(new ImageIcon(u));
			} else {
				AxLog.Error("Unable to resolve Image source path : \""
						+ imgpath + "\"");
			}

			// create text
			aboutText = new JTextPane();
			aboutText.setBounds(new Rectangle(144, 48, 256, 160));
			aboutText.setContentType("text/html");
			aboutText.setEditable(false);
			aboutText.setBackground(new Color(230, 230, 230));
			aboutText.setText(this.about);

			// Add items to panel
			mainPanel = new JPanel();
			mainPanel.setLayout(null);
			mainPanel.setBackground(new Color(230, 230, 230));
			mainPanel.add(aboutLogo, null);
			mainPanel.add(aboutTitle, null);
			mainPanel.add(aboutText, null);
		}
		return mainPanel;
	}

}
